package util;


public class SyncTest {

	private String data=null;
	private boolean completed=false;
	
	public synchronized void makeRealData(){
		if(this.completed)
			return;
//		获取数据的耗时操作，这里用sleep代替
		try{
			Thread.sleep(10000);
		}
		catch(Throwable t){}
		
		this.data="123456";
		this.completed=true;
		notifyAll();
	}
	
	
	public synchronized String getData(){
		while(!this.completed){
			try{
				wait();
			}catch(Throwable t){}
		}
		return this.data;
	}
	
	
	public boolean isCompleted(){
		
		return this.completed;
	}
	
	public static void main(String args[]){
//		SyncTest sync=new SyncTest();
		System.out.println("-------");
//		sync.makeRealData();
		
//		System.out.println(sync.getData());
		
		new Thread(){
			public void run(){
				try {
					Thread.sleep(10000);
					System.out.println("*66666");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}.start();
		
		System.out.println("*****");
		
	}
	
}


